<?php

class Client{
	
	public $id;
	public $name;
	public $email;
	public $password;
	public $type;
	
	function Client($id,$name,$email,$password,$type){
		$this->id=$id;
		$this->name=$name;
		$this->email=$email;
		$this->password=$password;
		$this->type=$type;
	}
	
	function save(){
		$sql = "INSERT INTO client 
				(client_name, 
				client_email, 
				client_password,
				client_type
				)
				VALUES
				('".$this->name."', 
				'".$this->email."', 
				'".$this->password."',
				'".$this->type."'
				);";
		mysql_query($sql) or die("Houver um erro ao tentar salvar o cliente");
	}
	
	function update(){
		$sql = "UPDATE client 
				SET
				client_name = '$this->name' , 
				client_email = '$this->email' , 
				client_password = '$this->password' , 
				client_type = '$this->type'
				
				WHERE
				client_id = '$this->id' ;";
		mysql_query($sql) or die("Houver um erro ao tentar alterar os dados do cliente");
	}
	
	function set($name,$email,$password,$type){
		$this->name=$name;
		$this->email=$email;
		$this->password=$password;
		$this->type=$type;
	}
	
	function delete(){
		$sql = "DELETE FROM client WHERE client_id = '$this->id' ;";
		mysql_query($sql) or die("Houver um erro ao tentar deletar os dados do cliente");
	}
	
	public function firstName(){
		$string = explode(" ", $this->name);
		return $string[0];
	}
	
}
?>